package com.carbonxsilicon.travellersbuddy;

import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.SeekBar;
import android.widget.NumberPicker;

public class FiltersActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_filters);
        SeekBar radiusBar = (SeekBar)findViewById(R.id.radiusBar);
        radiusBar.setOnSeekBarChangeListener (new calculateTrueRadius());
        Button doneButton = (Button)findViewById(R.id.doneButton);

        NumberPicker minAgePicker = (NumberPicker)findViewById(R.id.minAgePicker);
        minAgePicker.setMaxValue(80);
        minAgePicker.setMinValue(18);
        minAgePicker.setWrapSelectorWheel(false);
        minAgePicker.setOnValueChangedListener(new UpdateMin());

        NumberPicker maxAgePicker = (NumberPicker)findViewById(R.id.maxAgePicker);
        maxAgePicker.setMaxValue(80);
        maxAgePicker.setMinValue(18);
        maxAgePicker.setWrapSelectorWheel(false);


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.filters, menu);
        return true;
    }

    public class calculateTrueRadius implements SeekBar.OnSeekBarChangeListener {

        @Override
        public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) {

            TextView radiusText = (TextView)findViewById(R.id.radius);

            SeekBar radiusBar = (SeekBar)findViewById(R.id.radiusBar);

            switch (radiusBar.getProgress()) {

                case 0: radiusText.setText ("30m"); break;

                case 1: radiusText.setText ("100m"); break;

                case 2: radiusText.setText ("300m"); break;

                case 3: radiusText.setText ("1km"); break;

                case 4: radiusText.setText ("3km"); break;

                case 5: radiusText.setText ("Same city"); break;

                case 6: radiusText.setText ("Same country"); break;

                case 7: radiusText.setText ("Everywhere"); break;

                default: radiusText.setText ("radiusBar setText defaulted inside FilterActivity.java"); break;


            }


        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

    }

    public void onDone (View view) {
        this.finish();
        //Intent intent = new Intent(FiltersActivity.this, MainActivity.class);
        //startActivity(intent);
    }


    private class UpdateMin implements NumberPicker.OnValueChangeListener {

      public void onValueChange(NumberPicker minAgePicker, int oldVal, int newVal) {

          NumberPicker maxAgePicker = (NumberPicker)findViewById(R.id.maxAgePicker);

          maxAgePicker.setMinValue(newVal + 1);

          maxAgePicker.setWrapSelectorWheel(false); //for some reason it is necessary to tell Android this again
     }
    }
}
